# ===================================================================
#
#   makefile for calc
#
#   works for windows-32 and gnu unix
#
# ===================================================================

OUT = calc
HEADER_FILES = calc.h scanner.h SlkTree.h \
	       SlkParse.h SlkToken.h SlkError.h SlkAction.h SlkString.h
LLK_FILES = SlkParse.h SlkParse.cpp SlkTable.h SlkTable.cpp SlkString.h \
            SlkString.cpp 
GNU_OBJS = scanner.o calc.o SlkString.o SlkTree.o \
           SlkError.o SlkAction.o SlkParse.o SlkToken.o SlkTable.o 
OBJS = scanner.obj calc.obj SlkString.obj SlkTree.obj \
       SlkError.obj SlkAction.obj SlkParse.obj SlkToken.obj SlkTable.obj

# -------------------------------------------------------------------
# windows compiler flags and defines - msc (problem with getch())
# -------------------------------------------------------------------

MSC_CC = cl -c
MSC_LINK = link
MSC_DBG_CFLAGS = -Od -Zi -DDEBUG
MSC_DBG_LFLAGS = /DEBUG
MSC_CFLAGS = $(CINC) -nologo -Ox -W3 $(DBG_CFLAGS)
MSC_LFLAGS = /MAP /NOLOGO /OUT:$(OUT).exe $(DBG_LFLAGS)

# -------------------------------------------------------------------
# windows compiler flags and defines - ibm
# -------------------------------------------------------------------

IBM_CC = icc -c
IBM_LINK = ilink
IBM_DBG_CFLAGS = -O- -Ti+ -DDEBUG
IBM_DBG_LFLAGS = -debug
IBM_CFLAGS = $(CINC) -Q+ -O+ $(DBG_CFLAGS)
IBM_LFLAGS = /map /nologo /out:$(OUT) $(DBG_LFLAGS)

# -------------------------------------------------------------------
# gnu compiler flags and defines
# -------------------------------------------------------------------

GNU_CC = g++				# gcc -c
GNU_LINK = g++  			# gcc
GNU_CFLAGS = $(CINC) $(DBG_CFLAGS)
GNU_LFLAGS = -o$(OUT)
GNU_DBG_CFLAGS = -g -DDEBUG
GNU_DBG_LFLAGS =

# -------------------------------------------------------------------
# windows compiler flags and defines - watcom
# -------------------------------------------------------------------

WAT_CC = wcl386 -c
WAT_LINK = wcl386
WAT_CFLAGS = $(CINC) -Ox -zq -5r -fp5 $(DSLK)
WAT_LFLAGS = -x -k64K -fm -zq -fe=$(OUT)
WAT_DBG_CFLAGS = $(CINC) -zq -Od -d2 -DDEBUG
WAT_DBG_LFLAGS = -"DEBUG ALL"

# -------------------------------------------------------------------
# inference rules:
# -------------------------------------------------------------------

.c.o:
	$(CC) $(CFLAGS) $*.c

.c.obj:
	$(CC) $(CFLAGS) $*.c

# -------------------------------------------------------------------
# dependancies:
# -------------------------------------------------------------------

all:
	@$(MAKE) -nologo help

# -------------------------------------------------------------------
msc:
	@$(MAKE) -nologo "CC=$(MSC_CC)" "CFLAGS=$(MSC_CFLAGS)$(FLAG)" mscprog

mscdbg:
	@$(MAKE) -nologo "DBG_LFLAGS=$(MSC_DBG_LFLAGS)" "DBG_CFLAGS=$(MSC_DBG_CFLAGS)$(FLAG)" msc

mscprog: $(OBJS)
	$(MSC_LINK) $(MSC_LFLAGS) $**


# -------------------------------------------------------------------
ibm:
	@$(MAKE) -nologo "CC=$(IBM_CC)" "CFLAGS=$(IBM_CFLAGS)$(FLAG)" ibmprog

ibmdbg:
	@$(MAKE) -nologo "DBG_LFLAGS=$(IBM_DBG_LFLAGS)" "DBG_CFLAGS=$(IBM_DBG_CFLAGS)$(FLAG)" ibm

ibmprog: $(OBJS)
	$(IBM_LINK) $(IBM_LFLAGS) $**


# -------------------------------------------------------------------
gnu:
	@$(MAKE) "CC=$(GNU_CC)" "CFLAGS=$(GNU_CFLAGS)$(FLAG)" gnuprog

gnudbg:
	@$(MAKE) "DBG_LFLAGS=$(GNU_DBG_LFLAGS)" "DBG_CFLAGS=$(GNU_DBG_CFLAGS)$(FLAG)" gnu

gnuprog: $(GNU_OBJS)
	$(GNU_LINK) $(GNU_LFLAGS) $(GNU_OBJS)

# -------------------------------------------------------------------
wat:
	@$(MAKE) -nologo "CC=$(WAT_CC)" "CFLAGS=$(WAT_CFLAGS)$(FLAG)" watprog

watdbg:
	@$(MAKE) -nologo "CC=$(WAT_CC)" "CFLAGS=$(WAT_DBG_CFLAGS)$(FLAG)" watdbgprog

watprog: $(OBJS)
	$(WAT_LINK) $(WAT_LFLAGS) $**

watdbgprog: $(OBJS)
	$(WAT_LINK) $(WAT_LFLAGS) $(WAT_DBG_LFLAGS) $**

# -------------------------------------------------------------------
clean:
	rm -f *.o
	rm -f *.obj
	rm -f *.lst
	rm -f *.err
	rm -f *.map
	rm -f *.def
	rm -f *.exe
	rm -f *.out
	rm -f SlkParse.*
	rm -f SlkTable.*
	rm -f SlkString.*
	rm -f SlkParser.*
	rm -f SlkExecute.*
	rm -f SlkConstants.*
	rm -f SlkKeywords.txt
        @rm -f SlkTerminals.h
	rm -f $(OUT)
        rm -f xxx*

help:
	@echo Usage: make gnu or gnudbg 	    (gnu or debug-gnu target)
	@echo	       make ibm or ibmdbg
	@echo	       make msc or mscdbg
	@echo	       make wat or watdbg
	@echo	       make target "FLAG=-w3"       (add C compile flags)
	@echo	       make clean		    (clean directory files)

$(OBJS):	$(HEADER_FILES)

$(GNU_OBJS):	$(HEADER_FILES)

$(LLK_FILES):   calc.ll   makefile
       \slk\slk  -i  -v -C++ calc.ll > slk.out
	tail -n20 slk.out
